<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>博客发布</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
  <link rel="stylesheet" href="../../static/lib/editormd/css/editormd.min.css">
  <link rel="stylesheet" href="../../static/css/me.css">
  <link rel="icon" href="../static/favicon.ico">
</head>
<body>

  <!--导航-->
  <div th:replace="common/blogsHeader :: menu(1)"></div>

  <!--中间内容-->
  <div  class="m-container-small m-padded-tb-big">
    <div class="ui container">
      <form action="/admin/blogs/save" method="post" class="ui form">
        <input type="hidden" name="id" th:value="${param.id}">
        <input type="hidden" name="view" th:value="${blog} != null ? ${blog.view}">
        <input type="hidden" name="published">
        <div class="required field">
          <div class="ui left labeled input">
            <div class="ui selection compact teal basic dropdown label">
              <input type="hidden" value="原创" name="flag">
              <i class="dropdown icon"></i>
              <div class="text">原创</div>
              <div class="menu">
                <div class="item" data-value="原创">原创</div>
                <div class="item" data-value="转载">转载</div>
                <div class="item" data-value="翻译">翻译</div>
              </div>
            </div>
            <input type="text" name="title" placeholder="标题" th:value="${blog} != null ? ${blog.title}">
          </div>
        </div>

        <div class="field">
          <div id="md-content" style="z-index: 1 !important;">
            <textarea th:text="${blog} != null ? ${blog.content}" placeholder="博客内容" name="content" style="display: none"></textarea>
          </div>
        </div>

        <div class="two fields">
          <div class="field">
            <div class="ui left labeled action input">
              <label class="ui compact teal basic label">分类</label>
              <div class="ui fluid selection dropdown">
                <input type="hidden" name="typeId">
                <i class="dropdown icon"></i>
                <div class="default text">分类</div>
                <div class="menu">
                  <div th:each="type : ${types}" class="item" data-th-value="${type.id}">[[${type.name}]]</div>
                </div>
              </div>
            </div>
          </div>
          <div class="field">
            <div class="ui left labeled action input">
              <label class="ui compact teal basic label">标签</label>
              <div class="ui fluid selection multiple search  dropdown">
                <input type="hidden" name="tagIds">
                <i class="dropdown icon"></i>
                <div class="default text">标签</div>
                <div class="menu">
                  <div th:each="tag : ${tags}" class="item" data-th-value="${tag.id}">[[${tag.name}]]</div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div class="field">
          <div class="ui left labeled input">
            <label class="ui teal basic label">首图</label>
            <input type="text" name="firstPicture" placeholder="首图引用地址" th:value="${blog} != null ? ${blog.firstPicture}">
          </div>

        </div>

        <div class="inline fields">
          <div class="field">
            <div class="ui checkbox">
              <input type="checkbox" id="recommened" name="recommened" checked class="hidden" th:checked="${blog} != null ? ${blog.recommened}">
              <label for="recommened">推荐</label>
            </div>
          </div>
          <div class="field">
            <div class="ui checkbox">
              <input type="checkbox" id="shareStatement" name="shareStatement" class="hidden" th:checked="${blog} != null ? ${blog.shareStatement}">
              <label for="shareStatement">转载声明</label>
            </div>
          </div>
          <div class="field">
            <div class="ui checkbox">
              <input type="checkbox" id="aprreciation" name="aprreciation" class="hidden" th:checked="${blog} != null ? ${blog.aprreciation}">
              <label for="aprreciation">赞赏</label>
            </div>
          </div>
          <div class="field">
            <div class="ui checkbox">
              <input type="checkbox" id="commentabled" name="commentabled" class="hidden" th:checked="${blog} != null ? ${blog.commentabled}">
              <label for="commentabled">评论</label>
            </div>
          </div>
        </div>

        <div class="ui error message"></div>

        <div class="ui right aligned container">
          <button type="button" class="ui button" onclick="window.history.go(-1)" >返回</button>
          <button id="saveBtn" class="ui secondary button">保存</button>
          <button id="publishBtn" class="ui teal button">发布</button>
        </div>

      </form>
    </div>
  </div>

  <br>
  <br>
  <!--底部footer-->
  <div th:replace="common/blogsFooter :: #footer"></div>

<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
<script src="../../static/lib/editormd/editormd.min.js"></script>

  <script>

    //初始化Markdown编辑器
    var contentEditor;
    $(function() {
      contentEditor = editormd("md-content", {
        width   : "100%",
        height  : 640,
        syncScrolling : "single",
        path    : "../../static/lib/editormd/lib/"
      });
    });
    $('.menu.toggle').click(function () {
      $('.m-item').toggleClass('m-mobile-hide');
    });

    $('.ui.dropdown').dropdown({
      on : 'hover'
    });

    $('.ui.form').form({
      fields : {
        title : {
          identifier: 'title',
          rules: [{
            type : 'empty',
            prompt: '标题：请输入博客标题'
          }]
        }
      }
    });

    $('.ui.form').form({
      fields : {
        content : {
          identifier: 'content',
          rules: [{
            type : 'empty',
            prompt: '内容：请输入博客内容'
          }]
        }
      }
    });

    $('.ui.form').form({
      fields : {
        type : {
          identifier: 'type',
          rules: [{
            type : 'empty',
            prompt: '分类：请选择博客分类'
          }]
        }
      }
    });

    $('#saveBtn').click(function () {
      $('[name =published]').val(false);
    });
    $('#publishBtn').click(function () {
      $('[name =published]').val(true);
    });
  </script>
</body>
</html>